package com.kggs.springsnmp;

import com.kggs.springsnmp.utils.SnmpGet;
import com.kggs.springsnmp.utils.SnmpUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;
import java.util.Scanner;

@SpringBootApplication
public class SpringsnmpApplication {

    public static void main(String[] args) {
        while (true) {
            try {
                Scanner ipScanner = new Scanner(System.in);
                String ip = ipScanner.next();
                Long timeOut = 500L;
                boolean flag = SnmpGet.snmpPing(timeOut, ip, "public", "1.3.6.1.2.1.1.3.0");
                System.out.println("========>服务localhost连接状态：" + flag);
                String memory = SnmpUtil.collectMemory(ip);
                List<String> cpuList = SnmpUtil.collectCpu(ip);
                List<String> getList = SnmpGet.getSnmpLinux(ip, "public");
                if (cpuList != null && cpuList.size() >= 3) {
                    // cpu占用
                    double cpu = Double.parseDouble(cpuList.get(0) + "");
                    System.out.println("========>cpu占用：" + cpu);
                    // cpu总核数
                    String cpuSize = cpuList.get(1);
                    System.out.println("========>cpu总核数：" + cpuSize);
                    // cpu使用核数
                    String cpuUsedSize = cpuList.get(2);
                    System.out.println("========>cpu使用核数：" + cpuUsedSize);
                }
                if (getList != null && getList.size() >= 3) {

                    // 内存占用
                    double memoryValue = Double.parseDouble(memory);
                    System.out.println("========>内存占用：" + memoryValue);
                    // 内存大小
                    String memorySize = getList.get(2);
                    System.out.println("========>内存大小：" + memorySize);
                }

                // 磁盘占用
                double diskValue = SnmpGet.getSnmpDisk(ip, "1.3.6.1.2.1.25.2.3.1.6");
                System.out.println("========>磁盘占用：" + diskValue);

                // 磁盘大小
                double diskSize = SnmpGet.getSnmpDisk(ip, "1.3.6.1.2.1.25.2.3.1.5");

                System.out.println("========>磁盘大小：" + diskSize);
                double diskPercentage = (diskValue * 100 / diskSize);
                System.out.println("========>磁盘占用：" + diskPercentage);
            } catch (Exception e) {

            }
        }
        //SpringApplication.run(SpringsnmpApplication.class, args);
    }
}
